/**
 * Copyright © 2021 易久批信息技术有限公司. All rights reserved.
 */
package com.dysm.sort;

import java.util.*;

/**
 * 动图演示链接：https://images2017.cnblogs.com/blog/849589/201710/849589-20171015223238449-2146169197.gif
 * 冒泡排序：外层一次循环，数组中最大值移动到数组末尾
 * @author xiay
 * @since 2021/1/30 10:58 上午
 */
public class BubblingSortTest {

    public static void main(String[] args) {
        List<Integer> arr = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            int nextInt = new Random().nextInt(100);
            System.out.println(nextInt);
            arr.add(nextInt);
        }
//        int[] arr = {9,5,8,3,2,4,6,7};
        System.out.println(arr);

//        bobblingSort(arr);
        arr.sort(null);
        Collections.sort(arr);

        System.out.println(arr);
    }

    private static void bobblingSort(List<Integer> arr) {
        int size = arr.size();
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size - i - 1; j++) {
                if (arr.get(j) > arr.get(j + 1)) {
                    int temp = arr.get(j);
                    arr.set(j, arr.get(j + 1));
                    arr.set(j + 1, temp);
                }
            }
        }
    }


}
